package com.guoyw.seata.account.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.guoyw.seata.account.entity.TAccount;
import com.guoyw.seata.account.mapper.TAccountMapper;
import com.guoyw.seata.account.service.ITAccountService;
import com.guoyw.seata.common.dto.AccountDTO;
import com.guoyw.seata.common.enums.RspStatusEnum;
import com.guoyw.seata.common.response.ObjectResponse;
import org.apache.dubbo.config.annotation.Service;

/**
 * author: guoyw
 * create: 2020-09-19 16:22
 **/
@Service
public class ITAccountServiceImpl extends ServiceImpl<TAccountMapper,TAccount> implements ITAccountService{
 
  @Override
  public ObjectResponse decreaseAccount(AccountDTO accountDTO){
    int account = baseMapper.decreaseAccount(accountDTO.getUserId(), accountDTO.getAmount().doubleValue());
    ObjectResponse<Object> response = new ObjectResponse<>();
    if (account > 0){
      response.setStatus(RspStatusEnum.SUCCESS.getCode());
      response.setMessage(RspStatusEnum.SUCCESS.getMessage());
      return response;
    }
  
    response.setStatus(RspStatusEnum.FAIL.getCode());
    response.setMessage(RspStatusEnum.FAIL.getMessage());
    return response;
  }
}
